| Conditions | 1 |
| Paths | 2 |
| Total Lines | 54 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | /** |
||
| 25 | describe("Check CardDeck", function() { |
||
| 26 | describe("use default card deck", function() { |
||
| 27 | it("should be 104 cards", function() { |
||
| 28 | let deck = new CardDeck(); |
||
| 29 | let numberOfCards = deck.getNumberOfCards(); |
||
| 30 | |||
| 31 | assert.equal(numberOfCards, 104); |
||
| 32 | }); |
||
| 33 | |||
| 34 | it("id should be between 0 and 103", function() { |
||
| 35 | let deck = new CardDeck(); |
||
| 36 | let cards = deck.showAllCardsById(); |
||
| 37 | |||
| 38 | assert.equal(cards.length, 104); |
||
| 39 | assert.equal(cards[0], 0); |
||
| 40 | assert.equal(cards[51], 51); |
||
| 41 | assert.equal(cards[52], 0); |
||
| 42 | assert.equal(cards[103], 51); |
||
| 43 | }); |
||
| 44 | |||
| 45 | it("shuffle it", function() { |
||
| 46 | let deck = new CardDeck(); |
||
| 47 | let numberOfCards; |
||
| 48 | |||
| 49 | deck.shuffle(); |
||
| 50 | numberOfCards = deck.getNumberOfCards(); |
||
| 51 | |||
| 52 | assert.equal(numberOfCards, 104); |
||
| 53 | }); |
||
| 54 | |||
| 55 | it("get all cards, one by one", function() { |
||
| 56 | let deck = new CardDeck(); |
||
| 57 | let allCards = deck.showAllCardsById(); |
||
| 58 | let cardId; |
||
| 59 | let shuffledCards = []; |
||
| 60 | let equal; |
||
| 61 | |||
| 62 | deck.shuffle(); |
||
| 63 | while ((cardId = deck.getCard()) !== undefined) { |
||
| 64 | shuffledCards.push(cardId); |
||
| 65 | } |
||
| 66 | |||
| 67 | allCards.sort(compareInteger); |
||
| 68 | shuffledCards.sort(compareInteger); |
||
| 69 | |||
| 70 | equal = shuffledCards.length == allCards.length && |
||
| 71 | shuffledCards.every((element, index) => { |
||
| 72 | return element === allCards[index]; |
||
| 73 | }); |
||
| 74 | |||
| 75 | assert.equal(equal, true); |
||
| 76 | }); |
||
| 77 | }); |
||
| 78 | }); |
||
| 79 |